package com.yykj.user.center.server.controller.web;

import com.yykj.common.enums.ResultEnums;
import com.yykj.common.exception.NormalException;
import com.yykj.common.vo.ResultVO;
import com.yykj.user.center.server.form.GetOpenIdForm;
import com.yykj.user.center.server.service.WechatService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author chenl
 * @version 1.0
 * @date 2021/10/30 18:17
 */

@Api(tags = "微信相关接口")
@RestController
@RequestMapping("/api/wx")
@SuppressWarnings("unchecked")
public class WXController {
    @Autowired
    private WechatService wechatService;

    @Value("${spring.profiles.active}")
    private String active;

    @PostMapping("/getOpenId")
    @ApiOperation("获取OpenID")
    public ResultVO getOpenId(@RequestBody GetOpenIdForm getOpenIdForm){
        /*
        if("prod".equals(active)) {
            getOpenIdForm.setHospitalId(10001);
        }else{
            if(getOpenIdForm.getHospitalId() == 0){
                if("prod".equals(active)){
                    getOpenIdForm.setHospitalId(10001);
                }else{
                    getOpenIdForm.setHospitalId(10013);
                }
            }
        }*/

        if (getOpenIdForm==null){
            throw new NormalException(ResultEnums.NO_WXCODE_ERROR);
        }
        return ResultVO.success(wechatService.code2OpenId(getOpenIdForm));
    }
}
